package com.yunshipei.ui.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kyleduo.switchbutton.SwitchButton;
import com.yunshipei.base.BaseActivity;
import com.yunshipei.common.wedigt.YspTitleBar;
import com.yunshipei.common.Globals;
import com.yunshipei.enterplorer.R;
import com.yunshipei.manager.YspPreferences;
import com.yunshipei.utils.BaseUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MessageAlertActivity extends BaseActivity {

    @Bind(R.id.enter_title_bar)
    YspTitleBar mTitleBar;
    @Bind(R.id.ll_message_alert_container)
    LinearLayout mContainer;
    @Bind(R.id.sb_message_alert)
    SwitchButton mMessageAlertSwitch;
    private SharedPreferences mPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_alert);
        ButterKnife.bind(this);
        mTitleBar.setTitle("消息提醒设置");
        Items[] items = Items.values();
        for (int i = 0; i < items.length; i++) {
            View view = mContainer.getChildAt(i + 1);
            TextView textView = (TextView) view.findViewById(R.id.tv_item_content);
            ImageView imageView = (ImageView) view.findViewById(R.id.iv_right_indicator);
            textView.setText(items[i].name);
            imageView.setVisibility(items[i].visibility);
        }
        mPreferences = YspPreferences.getInstance().getSharedPreferences();
        //mMessageAlertSwitch.setTintColor(getResources().getColor(R.color.white));
        mMessageAlertSwitch.setBackColor(BaseUtil.getCurrentSwitchButtonColor(this));
        mMessageAlertSwitch.setCheckedImmediately(mPreferences.getBoolean(Globals.SP_MESSAGE_ALERT_ENABLE, true));
        mMessageAlertSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mPreferences.edit().putBoolean(Globals.SP_MESSAGE_ALERT_ENABLE, isChecked).apply();
            }
        });
    }

    private enum Items {
        MESSAGE_ALERT_ENABLE("接受新消息通知", View.GONE);
        private String name;
        private int visibility;

        Items(String name, int visibility) {
            this.name = name;
            this.visibility = visibility;
        }
    }
}
